package org.csu.laboratoryequipment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.csu.laboratoryequipment.common.CommonResponse;
import org.csu.laboratoryequipment.entity.Searchrecord;
import org.csu.laboratoryequipment.persistence.SearchrecordMapper;
import org.csu.laboratoryequipment.service.SearchrecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service("SearchrecordService")
public class SearchrecordServiceImpl implements SearchrecordService {

    @Autowired
    private SearchrecordMapper searchrecordMapper;
    public CommonResponse<List<Searchrecord>> getAllKeyword() {
        List<Searchrecord> searchrecordList = searchrecordMapper.selectList(null);
        System.out.println(searchrecordList);
        return CommonResponse.createForSuccess(searchrecordList);

    }

    public CommonResponse<List<Searchrecord>> getRank(){
        // 创建查询条件
        QueryWrapper<Searchrecord> queryWrapper = new QueryWrapper<>();
        // 按照columnName字段升序排序
        queryWrapper.orderByDesc("search_num");
        // 查询所有数据并按照条件排序
        List<Searchrecord>searchrecordList = searchrecordMapper.selectList(queryWrapper);
        return CommonResponse.createForSuccess(searchrecordList);
    }

    public CommonResponse<List<Searchrecord>> getKeywordByTime(Date startTime, Date endTime){
        // 创建查询条件
        QueryWrapper<Searchrecord> queryWrapper = new QueryWrapper<>();
        // 使用 between 方法指定搜索时间范围
        queryWrapper.between("search_time", startTime, endTime);
        // 查询符合条件的数据
        List<Searchrecord>searchrecordList = searchrecordMapper.selectList(queryWrapper);
        return CommonResponse.createForSuccess(searchrecordList);
    }

    public CommonResponse<List<Searchrecord>> getKeyword(){
        // 查询符合条件的数据
        List<Searchrecord>searchrecordList = searchrecordMapper.selectList(null);
        return CommonResponse.createForSuccess(searchrecordList);
    }
}
